<?php

namespace app\merchant\model;

use app\task\model\OrderModel;
use think\admin\Model;

/**
 * 商户支出记录模型
 * @class ExpenseRecordModel
 * @package app\merchant\model
 */
class ExpenseRecordModel extends Model
{
    protected $name = 'merchant_expense_record';

    /**
     * 字典-类型类型
     */
    public const TYPE__TASK_PAYMENT = 1;
    public const TYPE_DICT = [
        self::TYPE__TASK_PAYMENT => '订单任务报酬',
    ];

    /**
     * 类型获取器
     * @param $value
     * @param $data
     * @return string
     */
    public function getTypeTextAttr($value, $data)
    {
        return self::TYPE_DICT[$data['type']] ?? '';
    }

    /**
     * 关联商户
     */
    public function merchant(){
        return $this->belongsTo( MerchantModel::class, 'merchant_id', 'id');
    }

    /**
     * 关联执行订单
     */
    public function taskOrder(){
        return $this->hasOne(OrderModel::class, 'id', 'task_order_id');
    }
}
